// Copyright (c) 2007 Robin Boerdijk. All rights reserved.
//
// This software is licensed under the terms of the Microsoft Reciprocal License as described 
// in the file LICENSE.txt, which you should have received as part of this distribution. The 
// license terms are also available at http://www.opensource.org/licenses/ms-rl.html.

#ifndef wtk_GridBox_h_included
#define wtk_GridBox_h_included

#include "wtk/ContainerBox.h"

namespace wtk
{
	class GridBox : public ContainerBox
	{
	public:

		enum Flags
		{
			EqualizeColumnWidths = 0x1,
			EqualizeRowHeights = 0x2
		};

		GridBox(Count columnCount, Count expectedRowCount, int flags);

	protected:

		virtual SIZE CalculateMinimumContentSize();

		virtual long CalculateHorizontalElasticity();

		virtual long CalculateVerticalElasticity();

		virtual void LayoutContent(const POINT &position, const SIZE &size);

	private:

		Count m_columnCount;

		int m_flags;

		std::vector<long> m_cachedMinimumColumnWidths;

		long m_cachedLargestMinimumColumnWidth;

		std::vector<long> m_cachedMinimumRowHeights;

		long m_cachedLargestMinimumRowHeight;

		std::vector<long> m_cachedColumnElasticities;

		long m_cachedSmallestColumnElasticity;

		std::vector<long> m_cachedRowElasticities;

		long m_cachedSmallestRowElasticity;

		long CalculateMinimumColumnWidth(Count columnNumber);

		long CalculateMinimumRowHeight(Count rowNumber);

		long GetMinimumColumnWidth(Count columnNumber);

		long GetLargestMinimumColumnWidth();

		long GetMinimumRowHeight(Count rowNumber);

		long GetLargestMinimumRowHeight();

		long CalculateColumnElasticity(Count columnNumber);

		long CalculateRowElasticity(Count rowNumber);

		long GetColumnElasticity(Count columnNumber);

		long GetSmallestColumnElasticity();

		long GetRowElasticity(Count rowNumber);

		long GetSmallestRowElasticity();

		void LayoutRow(Count rowNumber, const POINT &position, const SIZE &size);

		Count GetRowCount();

		Box *GetBox(Count rowNumber, Count columnNumber);

		long GetCached(std::vector<long> &cache, Count index, long (GridBox::*calculateMethod)(Count));

		long CalculateLargest(Count count, long (GridBox::*getMethod)(Count));

		long CalculateSmallest(Count count, long (GridBox::*getMethod)(Count));
	};
}

#endif